<?php 
	$gv= new GiangVien();
	//$dsgv=$gv->ds();
	$cn=new ChuyenNganh();
	$dscn=$cn->ds();
	$tt=new TinhTrangGV();
	$dstt=$tt->ds();
	//-----------------//

	$sortcn="all";

	if (isset($_GET['sortbycn']) && $_GET['sortbycn']!=null){
		$sortcn=$_GET['sortbycn'];
	}

	$sorttt="all";
	if (isset($_GET['sortbytt'])){
		$sorttt=$_GET['sortbytt'];
	}

	$page=1;
	// kiem tra page
	if (!isset($_GET['page']) || $_GET['page'] ==null || !is_numeric($_GET['page'])){
	} else $page=$_GET['page'];

	$stt=($page-1)*10+1;

	$ds=array();
	
	if (strcmp($sortcn,"all")==0){

			if (strcmp($sorttt,"all")==0){
				// lay ds bt
				$ds=$gv->getSortBy($sortcn,$sorttt,$page);
			} else{
				$ds=$gv->getSortBy($sortcn,$sorttt,$page);
			}
	} else{

			if (strcmp($sorttt,"all")==0){
				$ds=$gv->getSortBy($sortcn,$sorttt,$page);
			} else {
				$ds=$gv->getSortBy($sortcn,$sorttt,$page);
			}
	}




?>

<div id="module">


	<h2><span>Danh sách giảng viên </span></h2>

	<?php echo "<form name=\"frmdsgv\" > "; ?>

	<div id="filter">
	
			
			<?php 

			   echo "Bộ Môn  :".Common::createSelect($dscn,"slCN",$sortcn,"YES","all","locTheoCNTT();");

			   echo "Tình trạng:".Common::createSelect($dstt,"slTTGV",$sorttt,"YES","all","locTheoCNTT();");
			?>
		
		
			
		
		
	</div>

<?php
	
	echo "<table>";
		echo "<thead>";
			echo "<tr id=\"tieude\">";
				echo "<th>STT</th>";
				echo "<th>Mã Giảng Viên</th>";
				echo "<th>Họ Tên</th>";
				echo "<th>Ngày Sinh</th>";			
				echo "<th>Hình ảnh</th>";
				echo "<th colspan=\"4\">Chức Năng</th>";
			echo "</tr>";
		echo "</thead>";

		// ds: danh sach sau khi loc
		

		
		//PhanTrang::pagingPage($ds,$page)
		if(count($ds)>0){
			foreach ($ds as $key) {
				echo "<tr>";
					echo "<td>".$stt."</td>";
					echo "<td>".$key->getMa()."</td>";
					echo "<td>".$key->getTen()." </td>";
					echo "<td>".NgayThang:: dinhDangXuat($key->getNgaySinh())." </td>";
					$url="";
					if (strcmp($key->getHinhAnh(),'')==0){
					$url=WEB_ROOT."manager/upload/hoso/giangvien/no_image.jpg";
				    } else {
				    	$url=WEB_ROOT."manager/upload/hoso/giangvien/".$key->getHinhAnh();
				    }
					echo "<td height=\"90\" width=\"90\"><img src=".$url." style=\"width:90%;height:90%; padding:5px; \"> </td>";
					echo "<td><a href=\"index.php?action=profile&id=".$key->getMa()." \" class=\"hinh\"><img src=\"../../../images/view.png\" title=\"Xem Hồ Sơ\" width=\"16\" height=\"16\"> </a></td>";
					echo "<td><a href=\"index.php?action=delete&id=".$key->getMa()."\" tilte=\"Xóa\"><img src=\"../../../images/hr.gif\" title=\"Xóa\" /></a></td>";
					echo "<td><a href=\"index.php?action=edit&id=".$key->getMa()."\" tilte=\"Sửa\"><img src=\"../../../images/edit-icon.gif\" title=\"Sửa\" /></a></td>";
					echo "<td><a href=\"#\" tilte=\"Khôi phục mật khẩu\"><img src=\"../../../images/view-refresh-16.png\" title=\"khôi phục mật khẩu\" width=\"16\" height=\"16\" /></a></td>";
				echo "</tr>";
				$stt++;
			}

			// phan trang			

			$filter=array("sortbycn"=>$sortcn,"sortbytt"=>$sorttt);
			$sumItems=PhanTrang::calSumPage($gv->getString($sortcn,$sorttt));

			if ($sumItems>10){
				echo "<tr style=\"text-align:left;\"> <td colspan=\"9\">Xem :".PhanTrang::comboLinking($sumItems,$page,$filter)."</td> </tr>";
			}

			echo "<tr style=\"text-align:center;\"> <td colspan=\"9\">".PhanTrang::linking($sumItems,$page,$filter)."</td> </tr>";
					

		}else{
			echo "<tr style=\"text-align:center;\" > <td colspan=\"9\"> Không có bản ghi nào được tìm thấy  </td> </tr>";
		}	

		echo "</table>";

		echo "</form>";



?>

</div>